import { useAgentChatStore } from '#/store';

enum conversationActionType {
  /** 接收消息 */
  acceptMsg = 'acceptMsg',
  /** 发送消息  */
  sendMsgResp = 'sendMsgResp',
  /** 发送消息返回状态 */
  sendMsgStatusResp = 'sendMsgStatusResp',
  /** 发送已读 */
  sendReadMsg = 'sendReadMsg',
  /** 接收已读 */
  sendReadMsgResp = 'sendReadMsgResp',
}

const agentChatStore = useAgentChatStore();
/**
 * @description 会话消息action处理
 * @param Data 后端传递数据
 * @param ws ws实例
 */
export function conversationHandle(Data: any, ws: WebSocket) {
  const { action } = Data;
  switch (action as conversationActionType) {
    // 接收消息
    case conversationActionType.acceptMsg: {
      break;
    }
    // 发送消息
    case conversationActionType.sendMsgResp: {
      agentChatStore.pushConversationList(Data.data.msgInfo);
      break;
    }
    // 发送消息状态
    case conversationActionType.sendMsgStatusResp: {
      agentChatStore.updateMsgStatus(Data.data.msgInfo);
      break;
    }
    // 发送已读
    case conversationActionType.sendReadMsg: {
      ws.send(JSON.stringify({ type: 'sendReadMsg', action: 'sendReadMsg' }));
      break;
    }
    // 接收已读
    case conversationActionType.sendReadMsgResp: {
      const data = Data;
      agentChatStore.setLeftMsgReadStatus(data.data.msgInfo);
      break;
    }
  }
}
